<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="template/template.xhtml">


        <ui:define name="title">
            <h:outputText value="#{msg['titulo']}"></h:outputText>
        </ui:define>

        <ui:define name="body">

            <f:loadBundle basename="categoria" var="msg"/>

            <h:form id="formLista">

                <p:panel header="#{msg['tituloPrograma']}">
                    <p:dataTable id="datalist" value="#{categoriaM.items}" var="item"
                                 selectionMode="single" selection="#{categoriaM.selected}"
                                 paginator="true"
                                 rowKey="#{item.codigo}"
                                 rows="10"
                                 rowsPerPageTemplate="5,10,25,50,100"
                                 >

                        <p:ajax event="rowSelect"   update="btnApagar btnCriar btEditar"/>
                        <p:ajax event="rowUnselect" update="btnApagar btnCriar btEditar"/>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{msg['codigo']}"/>
                            </f:facet>
                            <h:outputText value="#{item.codigo}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{msg['nome']}"/>
                            </f:facet>
                            <h:outputText value="#{item.nome}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{msg['descricao']}"/>
                            </f:facet>
                            <h:outputText value="#{item.descricao}"/>
                        </p:column>


                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{msg['ativa']}" 
                                              title="#{msg['ativa.tilte']}"/>
                            </f:facet>
                            <p:selectBooleanButton disabled="true"  value="#{item.ativa}" onLabel="#{padrao['sim']}"
                                                   offLabel="#{padrao['nao']}" 
                                                   onIcon="ui-icon-check" offIcon="ui-icon-close" />
                        </p:column>


                        <f:facet name="footer">
                            <p:commandButton id="btnCriar" icon="ui-icon-plus"   value="#{padrao['criar']}"  
                                             oncomplete="PF('dialogManutencao').show()" update=":formManutencao :mensagem "
                                             action="#{categoriaM.novaInstancia}" />


                            <p:commandButton id="btEditar" icon="ui-icon-plus"   value="#{padrao['editar']}"  
                                             oncomplete="PF('dialogManutencao').show()" 
                                             update=":formManutencao :mensagem " disabled="#{categoriaM.selected eq null}" />

                            <p:commandButton id="btnApagar" icon="ui-icon-plus" 
                                             value="#{padrao['excluir']}"  
                                             action="#{categoriaM.remover}"
                                             ajax="false" disabled="#{categoriaM.selected eq null}" />
                        </f:facet>
                    </p:dataTable>





                </p:panel>
            </h:form>

            <p:dialog   widgetVar="dialogManutencao" modal="true" resizable="false" 
                        appendTo="@(body)" header="#{padrao['criarNovoRegistro']}" width="600px">
                <h:form id="formManutencao">
                    <p:panelGrid id="panelManutencao" columns="2" style="    border-style:none; width: 100%;" >
                        <p:outputLabel value="#{msg['codigo']}" for="codigo" />
                        <p:inputText value="#{categoriaM.selected.codigo}" disabled="true" id="codigo"  />

                        <p:outputLabel value="#{msg['nome']}" for="nome" />
                        <p:inputText value="#{categoriaM.selected.nome}" id="nome"  />

                        <p:outputLabel value="#{msg['descricao']}" for="descricao" />
                        <p:inputText value="#{categoriaM.selected.descricao}" 
                                     id="descricao"  />



                        <p:outputLabel value="#{msg['permissoes']}"                                       for="permissoes" />

                        <p:pickList value="#{categoriaM.dualListModelProgramas}"  
                                    var="programa" 
                                    id="permissoes"
                                    itemLabel="#{programa.nome}"  
                                    itemValue="#{programa}" converter="programaConverter"  
                                    >  

                        </p:pickList>  


                        <p:outputLabel value="#{msg['ativo']}"  
                                       for="ativo" />

                        <p:selectBooleanButton id="ativo" 
                                               value="#{categoriaM.selected.ativa}"
                                               onLabel="#{padrao['sim']}"
                                               offLabel="#{padrao['nao']}" 
                                               onIcon="ui-icon-check"
                                               offIcon="ui-icon-close" />


                        <p:commandButton id="btnCancelar" icon="ui-icon-plus"   value="#{padrao['cancelar']}" 
                                         action="#{categoriaM.cancelar}" update="@form"    
                                         oncomplete="PF('dialogManutencao').hide()" />



                        <p:commandButton id="btnConfirmar" icon="ui-icon-plus"   
                                         value="#{padrao['confirmar']}" action="#{categoriaM.salvarAtualizar}"  
                                         oncomplete="PF('dialogManutencao').hide()" 
                                         update=":formLista :mensagem @form" />

                    </p:panelGrid>
                </h:form>
            </p:dialog>         
        </ui:define>
    </ui:composition>

</html>
